/********************************************************************************
 *      Copyright:  (C) 2022 xiezongyi<1764417007@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  tlv_server.h
 *    Description:  This head file 
 *
 *        Version:  1.0.0(12/08/22)
 *         Author:  xiezongyi <1764417007@qq.com>
 *      ChangeLog:  1, Release initial version on "12/08/22 15:38:30"
 *                 
 ********************************************************************************/
#ifndef _TLV_SERVER_H_
#define _TLV_SERVER_H_

#include <stdint.h>

#define PORT 9999

#define PACK_HEADER        0xFD

/* TLV packet fixed segement size, 1B Head, 1B Tag, 1B length, 2B CRC16, total 5B. */
#define TLV_FIXED_SIZE     5

/* TLV packet Minimum size is fixed bytes + 1 byte data */
#define TLV_MIN_SIZE       (TLV_FIXED_SIZE+1)
#define TLV_MAX_SIZE       32    /* all TLV packet length are no more than 32 bytes */


/* Tag definition */
enum
{
    TAG_SN=1,
    TAG_TEMP,
    TAG_TIME,
};

/* parser TLV pack data */
int parser_tlvpack(char *buf, int bytes, char *tlv_buf, int *tlv_size);

/* change char type to unsigned short */
int bytes_to_ushort(unsigned char *buf, int len);

/* print buf data in hex and string mode  */
void dump_buf(char *data, int len);

#endif
